#ifndef CLIENT_H_
#define CLIENT_H_
#include "NetworkMsg.h"
#include <unordered_map>
using namespace std;

#define MYVER 1
#define CONNECTTIMEOUT 100000

#define ALIVETIME 0.1f
#define SERVERALIVETIME 1.0f
#define OBJECTCOUNTTIME 0.1f

//Return values
#define SUCCESS 0
#define CONNECT_TIMEOUT -2
#define ADDRESS_ERROR -3
#define SERVER_TIMEOUT -4
#define NOT_RUNNING -5
#define LOG_IN_FAILED -6

struct Command
{
	bool dirty;
	char Horizontal;
	bool Jump;
	bool Fire;
	float Angle;
};
//Everything
//char robots
//short bullets

struct Robot
{
	int ID;
	float PosX;
	float PosY;
	float VelX;
	float VelY;
	float AngleGun;
	float Red;
	float Blue;
	float Green;
};

struct BulletSpawns
{
	int ID;
	float PosX;
	float PosY;
	float VelX;
	float VelY;
	int Owner;
	float power;
};
class ObjectManager;

enum MESSAGETYPE { CL_CONNECT = 0,CL_DISCONNECT,CL_COMMAND,CL_GET_ALL,CL_GET_OBJECT_COUNT,CL_ALIVE,CL_LOG_IN,CL_LOG_OUT};
enum SERVERMESSAGE { SV_CONNECT_RECV = 0,SV_ROBOTS,SV_BULLETS,SV_OBJECT_COUNT,SV_EVERYTHING,SV_LOGGED_IN,SV_LOG_IN_FAIL,SV_LOGGED_OUT};
class Client
{
	ObjectManager* objectManager;
	SOCKET clSocket;
	unsigned int uiTimeStamp;
	SOCKADDR_IN sa;
	bool Running;
	bool Connected;
	unsigned int mySequence;
	unsigned int LastSeverSequence;
	float myTimer;
	float serverTimer;
	float objectCountTimer;
	char myID;
	bool LoggedIn;
	bool LoggedInFailed;
	Command commandToSend;

	unordered_map< unsigned int, unsigned int > m_umServerToLocal;

public:
	int Init(char* address, short port);
	int Connect(float red, float green, float blue);
	void Stop();
	void SendMessage(NetworkMsg msg);
	int Update(float dT);
	void UpdateLoop();
	void ParseMessage(NetworkMsg msg);
	int LogIn(char* userName, char* passWord);
	void LogOut();
	void Move(char commandType);
	void SetAngle(float angle);
	void ButtonPress(char button);
	void CullRobots();
};



#endif